﻿using System;
using System.Collections.Generic;

namespace WSManager.Wpf
{
    class GenericComparer<T>: IEqualityComparer<T>
    {
        private Func<T, T, bool> isEquals;
        private Func<T, int> getHash;

        public GenericComparer(Func<T, T, bool> isEquals, Func<T, int> getHash = null)
        {
            this.isEquals = isEquals;
            this.getHash = getHash ?? (x => x.GetHashCode());
        }

        public bool Equals(T x, T y)
        {
            return isEquals(x, y);
        }

        public int GetHashCode(T obj)
        {
            return getHash(obj);
        }

    }
}
